package com.dragon.client.controller.auth;

import com.dragon.client.config.annotation.Login;
import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.auth.IModRoleService;
import com.dragon.repository.domain.dto.ModRoleDTO;
import com.dragon.repository.domain.vo.ModRoleVO;
import com.dragon.repository.entity.ModRole;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 模块角色表 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-07-20
 */
@RestController
@RequestMapping("modRole")
@Api(tags = "角色控制台")
public class ModRoleController {

    @Autowired
    IModRoleService service;

    @GetMapping("list")
    @ApiOperation("角色控制台列表")
    public ResponseData list(@ApiParam(hidden = true) @Login Integer id){
        return ResponseData.success(service.listModRole(id));
    }

    @PostMapping("add")
    @ApiOperation("新增")
    public ResponseData add(@RequestBody @Validated(Insert.class) ModRoleVO vo){
        service.addModRole(ModRoleVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("chooseMod")
    @ApiOperation("选择模块")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role", value = "角色id", required = true, type = "int"),
            @ApiImplicitParam(name = "modIds", value = "模块ids", required = true, type = "String")
    })
    public ResponseData chooseMod(@RequestParam Integer roleId , @RequestParam String modIds){
        service.chooseMod(roleId,modIds);
        return ResponseData.success();
    }


    @GetMapping("modList")
    @ApiOperation("获取列表")
    public ResponseData selectModListByRoleId(@ApiParam(name = "roleId",required = true,type = "int",value = "角色id")@RequestParam Integer roleId){
        List<ModRole> result = service.selectModListByRoleId(roleId);
        return ResponseData.success(ModRoleDTO.convertList(result));
    }

}
